<?php
declare (strict_types = 1);

namespace app\command;

use app\common\lib\Identity;
use app\common\lib\RedisManage;
use http\Message;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;

class Duplicate extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('duplicate')
            ->setDescription('the app\command\duplicate command');
    }

    protected function execute(Input $input, Output $output)
    {
		//禁用
		exit;
        $redis = RedisManage::instance()->getRedis();
        $time = time();
        $i = 0;
        $appid_ = 0;
        $secret_ = 0;
        $access_token_ = 0;
        while(time()-$time < 1800){
            try{
                $appid = Identity::appid();
                if($redis->sIsMember('appid',$appid)){
                    ++$appid_;
                    file_put_contents(app()->getRootPath().'runtime/appid.log','共'.$i.'个,重复了'.$appid_.'个'.PHP_EOL,FILE_APPEND);
                }
                $redis->sAdd('appid',$appid);

                $secret = Identity::secret($appid);
                if($redis->sIsMember('secret',$secret)){
                    ++$secret_;
                    file_put_contents(app()->getRootPath().'runtime/secret.log','共'.$i.'个,重复了'.$secret_.'个'.PHP_EOL,FILE_APPEND);
                }
                $redis->sAdd('secret',$secret);

                $access_token = Identity::accessToken($appid,$secret,true);
                if($redis->sIsMember('access_token',$access_token)){
                    ++$access_token_;
                    file_put_contents(app()->getRootPath().'runtime/access_token.log','共'.$i.'个,重复了'.$access_token_.'个,'.$access_token.PHP_EOL,FILE_APPEND);
                }
                $redis->sAdd('access_token',$access_token);
                ++$i;
                $message = <<<MESS
已生成{$i}个,appid重复了{$appid_},secret重复了{$secret_},access_token重复了{$access_token_}
MESS;

                $output->writeln($message);
            }catch (\Exception $exception){
                $output->writeln($exception->getMessage());
                $output->writeln($exception->getFile().':'.$exception->getLine());

            }
        }
    }
}
